﻿using System.Runtime.Serialization;
using UnityEngine;
using UnityEngine.Scripting;

namespace GMME.Model.Rtm.Notify
{
    [DataContract]
    [Preserve]
    public class ReceiveRtmChannelMessageNotify : RtmMessageNotify
    {
        /**
         * 开发者传入的频道Id
         */
        [DataMember(Name = "channelId")]
        [Preserve]
        public string ChannelId { get; set; }

#if UNITY_ANDROID
        internal static ReceiveRtmChannelMessageNotify ConvertReceiveRtmChannelMessageNotify(
            AndroidJavaObject javaObject)
        {
            if (javaObject != null)
            {
                ReceiveRtmChannelMessageNotify receiveRtmChannelMessageNotify = new();
                receiveRtmChannelMessageNotify.ChannelId = javaObject.Call<string>("getChannelId");

                receiveRtmChannelMessageNotify.ServerMsgId = javaObject.Call<string>("getServerMsgId");
                receiveRtmChannelMessageNotify.ClientMsgId = javaObject.Call<string>("getClientMsgId");
                receiveRtmChannelMessageNotify.Timestamp = javaObject.Call<long>("getTimestamp");
                receiveRtmChannelMessageNotify.SenderId = javaObject.Call<string>("getSenderId");
                receiveRtmChannelMessageNotify.IsFromOpenApi = javaObject.Call<bool>("isFromOpenApi");


                receiveRtmChannelMessageNotify.MessageType = javaObject.Call<int>("getMessageType");
                receiveRtmChannelMessageNotify.MessageString = javaObject.Call<string>("getMessageString");
                receiveRtmChannelMessageNotify.MessageBytes = javaObject.Call<byte[]>("getMessageBytes");

                return receiveRtmChannelMessageNotify;
            }

            return null;
        }

#endif
    }
}